home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.06 Jun 89 / Basic Source / Help Call Projects / GetHelp.p < prev    next >
Encoding:
Text File  |  1989-04-15  |  3.1 KB  |  87 lines  |  [TEXT/PJMM]

  1. unit getHelp;
  2.  
  3. {Procedure for Calling the Help desk accessory }
  4. {for Context Sensitive Help and Extended Alert Messages}
  5. {{Copyright ©1988 , Help Software , Inc . }
  6. { Modified by Dave Kelly for MacTutor, April 1989 }
  7. { Source code in Lightspeed Pascal 2.0 }
  8. { This procedure will open the Help DA and pass it the number }
  9. {of the Help message to be displayed . }
  10. { Under MultiFinder , this procedure will install the Help DA in * the  }
  11. { application heap . }
  12.  
  13. interface
  14.  
  15.     function main (message: integer): integer;
  16.                                 { message: number of message to display }
  17.  
  18.  
  19. implementation
  20.  
  21.     function main (message: integer): integer;
  22.  
  23.         type
  24.             LongPtr = ^LONGINT;
  25.  
  26.         var
  27.             error, Help: integer;        { Help is the desk accessory refnum }
  28.             param: ParamBlockRec;        { parameter block for the control call }
  29.             myhandle: Handle;
  30.             name: string;
  31.             theKeyMap: longint;
  32.             theKeyMapPtr: LongPtr;
  33.  
  34.     begin
  35.         theKeyMap := $178;
  36.         Help := 0;
  37.         name := CONCAT(CHR(0), 'Help');
  38.         SetResLoad(FALSE);            { Don't load it,}
  39.         myhandle := GetNamedResource('DRVR', name);  { ...just get the handle }
  40.         error := ResError;            { -192 = Help not available }
  41.         SetResLoad(TRUE);             { Reset SetResLoad }
  42.         if (error = noErr) then
  43.             begin                        { Help is available}
  44.                 EmptyHandle(myhandle);      { Try to purge the Help DA }
  45.                 if myhandle = nil then      { If handle=NIL, it's not loaded, }
  46.                     begin
  47.                         ResrvMem(SizeResource(myhandle));  { ...reserve memory for it }
  48.                         error := MemError;         { -108 = Not enough room in heap }
  49.                     end;
  50.                 if error = noErr then       { all go .. . }
  51.                     begin
  52.                         LongPtr(theKeyMap)^ := BitOr(LongPtr(theKeyMap)^, 4);
  53.                                 { Required to work properly with MultiFinder }
  54.                                 { Press the Option key }
  55.                         Help := OpenDeskAcc(name);    { Open the Help DA }
  56.  
  57.                         if (Help < 0) and (Help = (WindowPeek(FrontWindow)^.windowKind)) then
  58.  
  59.                                     { If the Help DA open }
  60.                             begin
  61.                                 param.ioCompletion := nil;
  62.                                 param.ioRefNum := Help;        { Help is the value returned}
  63.                                     { by the OpenDeskAcc call }
  64.                                 param.csCode := 5000;          { 5000 tells the Help DA: "This is}
  65.                                     {a context sensitive help call" }
  66.                                 param.csParam[0] := message;   { Help message to display }
  67.                                 error := PBControl(@param, TRUE);
  68.         { An asynchronous control call that tells the Help DA what to show ! }
  69.                             end               { end if Is the Help DA open }
  70.                         else
  71.                             begin
  72.                                 error := 1;     { Let the caller know that the Help DA was not opened }
  73.                                 LongPtr(theKeyMap)^ := 0;       { Release the Option key  }
  74.                             end;
  75.                     end
  76.                 else
  77.                     begin
  78.                 { Display an Alert : Not enough memory to open Help DA  }
  79.                     end
  80.             end          {Help is Available }
  81.         else
  82.             begin
  83.                 { Display an Alert : Help DA not available }
  84.             end;    { End No Help Available}
  85.         main := error;    {for function result}
  86.     end;           {of GetHelp ( message ) function }
  87. end.